# #太阳系简图
#
# import matplotlib.pyplot as plt
# import numpy as np
# from matplotlib.patches import Ellipse
#
# # 设置中文字体
# plt.rcParams['font.sans-serif'] = ['SimHei']  # 使用 SimHei 字体
# plt.rcParams['axes.unicode_minus'] = False  # 解决负号显示问题
#
# # 定义行星的轨道参数
# planets = {
#     '水星': {'a': 0.39, 'b': 0.38, 'angle': 7},
#     '金星': {'a': 0.72, 'b': 0.72, 'angle': 3.4},
#     '地球': {'a': 1.00, 'b': 1.00, 'angle': 0},
#     '火星': {'a': 1.52, 'b': 1.51, 'angle': 1.85},
#     '木星': {'a': 5.20, 'b': 5.19, 'angle': 1.3},
#     '土星': {'a': 9.58, 'b': 9.54, 'angle': 2.49},
#     '天王星': {'a': 19.22, 'b': 19.18, 'angle': 0.77},
#     '海王星': {'a': 30.05, 'b': 30.00, 'angle': 1.77}
# }
#
# fig, ax = plt.subplots(subplot_kw={'aspect': 'equal'})
#
# # 添加太阳
# sun = plt.Circle((0, 0), 0.1, color='yellow')
# ax.add_artist(sun)
#
# # 设置注释偏移量
# offsets = {
#     '水星': (0.5, 0.5),
#     '金星': (0.5, -0.5),
#     '地球': (-0.5, -0.5),
#     '火星': (-0.5, 0.5),
#     '木星': (1.0, 1.0),
#     '土星': (1.0, -1.0),
#     '天王星': (-1.0, -1.0),
#     '海王星': (-1.0, 1.0)
# }
#
# # 绘制每个行星的轨道和注释
# for planet, params in planets.items():
#     ellipse = Ellipse(xy=(0, 0), width=2*params['a'], height=2*params['b'], angle=params['angle'], edgecolor='blue', facecolor='none')
#     ax.add_artist(ellipse)
#     # 使用注释箭头标注行星名称
#     ax.annotate(planet,
#                 xy=(params['a'], 0), xycoords='data',
#                 xytext=(params['a'] + offsets[planet][0], offsets[planet][1]), textcoords='data',
#                 arrowprops=dict(arrowstyle="->", connectionstyle="arc3"),
#                 fontsize=8, color='red')
#
# # 生成随机小行星带
# num_asteroids = 1000
# asteroid_radii = np.random.uniform(2.1, 3.3, num_asteroids)  # 小行星带大约在2.1 AU到3.3 AU之间
# asteroid_angles = np.random.uniform(0, 2*np.pi, num_asteroids)
#
# # 转换极坐标到直角坐标
# asteroid_x = asteroid_radii * np.cos(asteroid_angles)
# asteroid_y = asteroid_radii * np.sin(asteroid_angles)
#
# # 绘制小行星带
# ax.scatter(asteroid_x, asteroid_y, s=1, color='gray')
#
# # 设置图形边界
# ax.set_xlim(-35, 35)
# ax.set_ylim(-35, 35)
# ax.set_xlabel('距离 (AU)')
# ax.set_ylabel('距离 (AU)')
# ax.set_title('太阳系行星轨道图和小行星带')
#
# plt.grid(True)
# plt.show()

#三维绘图
import matplotlib.pyplot as plt
import numpy as np
from mpl_toolkits.mplot3d import Axes3D

# 设置中文字体
plt.rcParams['font.sans-serif'] = ['SimHei']  # 使用 SimHei 字体
plt.rcParams['axes.unicode_minus'] = False  # 解决负号显示问题

# 定义行星的轨道参数
planets = {
    '水星': {'a': 0.39, 'b': 0.38, 'angle': 7},
    '金星': {'a': 0.72, 'b': 0.72, 'angle': 3.4},
    '地球': {'a': 1.00, 'b': 1.00, 'angle': 0},
    '火星': {'a': 1.52, 'b': 1.51, 'angle': 1.85},
    '木星': {'a': 5.20, 'b': 5.19, 'angle': 1.3},
    '土星': {'a': 9.58, 'b': 9.54, 'angle': 2.49},
    '天王星': {'a': 19.22, 'b': 19.18, 'angle': 0.77},
    '海王星': {'a': 30.05, 'b': 30.00, 'angle': 1.77}
}

fig = plt.figure()
ax = fig.add_subplot(111, projection='3d')

# 添加太阳
ax.scatter(0, 0, 0, color='yellow', s=100, label='太阳')

# 绘制每个行星的轨道
for planet, params in planets.items():
    a = params['a']
    b = params['b']
    angle = np.deg2rad(params['angle'])

    # 生成轨道点
    theta = np.linspace(0, 2 * np.pi, 100)
    x = a * np.cos(theta)
    y = b * np.sin(theta)

    # 考虑轨道倾角
    z = y * np.sin(angle)
    y = y * np.cos(angle)

    # 绘制轨道
    ax.plot(x, y, z, label=planet)

# 设置图形边界和标签
ax.set_xlim(-35, 35)
ax.set_ylim(-35, 35)
ax.set_zlim(-5, 5)
ax.set_xlabel('X (AU)')
ax.set_ylabel('Y (AU)')
ax.set_zlabel('Z (AU)')
ax.set_title('太阳系行星轨道图')
ax.legend()

plt.show()